# encoding: utf-8
from flask_marshmallow import base_fields

from app.modules.project.schemas import ProjectBaseSchema
from flask_restplus_patched import ModelSchema
from app.modules.common.schemas import BaseSchema
from app.modules.projectPlan.schemas import PlanSchema,UserBaseSchema
from .models import IntegrationEditionChengeRecord,IntegrationInfo,IntegrationOnlineDesc


class IntegrationBaseSchema(ModelSchema):
    members = base_fields.Nested(
        UserBaseSchema,
        many = True
    )
    projects = base_fields.Nested(
        ProjectBaseSchema,
        many = True
    )
    class Meta:
        model = IntegrationInfo
        fields = (
            'integration_id',
            'integration_cycle',
            'integration_name',
            'integration_date',
            'online_date',
            'integration_status',
            'integration_desc',
            'members',
            'isEmergency',
            'projects',
        )

class IntegrationOnlineDescBaseSchema(ModelSchema):
    class Meta:
        model = IntegrationOnlineDesc
        fields = (
            'id',
            'integration_id',
            'create_date',
            'update_date',
            'user_id',
            'real_name',
            'desc',
            'index',
            'file_name',
            'file_path',
        )

class IntegrationEditionChengeRecordBaseSchema(ModelSchema):
    class Meta:
        model =IntegrationEditionChengeRecord
        fields = (
            'record_id',
            'integration_id',
            'integration_name',
            'plan_id',
            'plan_name',
            'create_date',
            'user_id',
            'user_realname',
            'user_role',
            'trunk_name',
            'old_project',
            'old_edition',
            'old_status',
            'new_project',
            'new_edition',
            'new_status',
            'key',
            'integration_status',
        )


class IntegrationListSchema(BaseSchema):
    data = base_fields.Nested(
        IntegrationBaseSchema,
        many = True
    )

    class Meta:
        fields = BaseSchema.Meta.fields + (
            'data',
        )


class IntegrationPlanListSchema(BaseSchema):
    data = base_fields.Nested(
        PlanSchema,
        many = True
    )

    class Meta:
        fields = BaseSchema.Meta.fields + (
            'data',
        )


class EditionChangeRecordListSchema(BaseSchema):
    data = base_fields.Nested(
        IntegrationEditionChengeRecordBaseSchema,
        many = True
    )

    class Meta:
        fields = BaseSchema.Meta.fields + (
            'data',
        )

class AutoDrawSqlStatusBaseSchema(ModelSchema):
    class Meta:
        fields = (
            'status',
            'date',
            'projects',
            'desc',
        )
class AutoDrawSqlStatusSchema(BaseSchema):
    data = base_fields.Nested(
        AutoDrawSqlStatusBaseSchema,
        many = False
    )

    class Meta:
        fields = BaseSchema.Meta.fields + (
            'data',
        )

class IntegrationOnlineDescListSchema(BaseSchema):
    data = base_fields.Nested(
        IntegrationOnlineDescBaseSchema,
        many = True
    )

    class Meta:
        fields = BaseSchema.Meta.fields + (
            'data',
        )